<template>
	<view class="index">
		<view class="top">
			<view class="search">
				<image src="@/static/index/ss.png" mode=""></image>
				<input type="text" placeholder="搜索商品" placeholder-style="color:#B8B9BD" disabled
					@click="toPage('./goods-search')" />
			</view>
		</view>
		<!-- 轮播图 -->
		<view class="swiper">
			<swiper :indicator-dots="true" circular="true" indicator-color="#fff" indicator-active-color="#ccc"
				:autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="(item,index) in banner" :key="index"
					@click="toPage(`/pages/goodsdetail/index?id=${item.href}`)">
					<view class="swiper-item">
						<image :src="item.url | getImg" mode=""></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 导航栏 -->
		<view class="nav">
			<view class="nav-tab" v-for="(item,index) in tagList" :key="index"
				@click="toPage(`/pages/classlist/goods?type=${goods_type}&id=${item.id}`)">
				<view class="navbox">
					<image :src="item.img_url | getImg" mode=""></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>
		<!-- 专区 -->
		<view class="hot">
			<view class="goods">
				<view class="goodsitem" v-for="(item,index) in goods" :key='item.id'
					@click="toPage('/pages/goodsdetail/index?id='+item.id)">
					<image :src="item.logo_url | getImg" mode="aspectFill"></image>
					<text class="name">{{item.name}}</text>
					<!-- <text class="des">{{item.sketch}}</text> -->
					<view class="price">
						<view>
							￥<text class="pricenum">{{item.price}}</text>
						</view>
						<view class="sell">
							已售:{{item.sell}}
						</view>
					</view>
					<view class="price old">
						<view>
							<text class="oldprice">￥{{item.old_price}}</text>
						</view>
						<view class="sell">
							赠送积分:{{item.song_ji}}
						</view>
					</view>
				</view>
				<view class="no-list" v-if="goods.length == 0 ">
					- 暂无数据 -
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		Home,
		hotGoods,
		CheckShop,
		GoodsList,
		share
	} from '@/api/api.js'
	import {
		ContactShop
	} from "@/api/user.js"
	export default {
		data() {
			return {
				goods: [],
				goods2: [],
				banner: [],
				goods_type: '',
				conf: [],
				last_page: 1,
				page: 1,
				tagList: [],
				info: [],
				is_login: false,
				shop_code: '',
				type: ''
			}
		},
		onLoad() {
			this.GoodsList()
			this.IndexGoods()
			this.share()
		},
		onShareAppMessage() {
			return {
				path: `/pages/register/index?type=${this.type}&shop_code=${this.shop_code}`
			}
		},
		onShow() {
			this.ContactShop()
			this.GoodsList()
			// this.hotGoods()
			// this.CheckShop()
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: '/pages/register/childshop'
			})
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.GoodsList()
			}
		},
		methods: {
			share() {
				share().then(res => {
					this.shop_code = res.data.shop_code
					this.type = res.data.type
				})
			},
			GoodsList() {
				GoodsList({
					goods_type: '',
					page: this.page
				}).then(res => {
					if (res.status == 1) {
						this.tagList = res.data.class
						this.goods = res.data.goods.data
						this.last_page = res.data.goods.last_page
					}
				})
			},
			ContactShop() {
				ContactShop().then(res => {
					if (res.status == 1) {
						this.info = res.data
						if (this.info) {
							uni.setNavigationBarTitle({
								title: this.info.shop_name || '新雅行'
							})
						} else {
							uni.setNavigationBarTitle({
								title: '新雅行'
							})
						}

					}
				})
			},
			CheckShop() {
				CheckShop().then(res => {
					if (res.status == 1) {
						if (res.data.type == 2) {
							uni.redirectTo({
								url: '/pages/register/childshop'
							})
						} else if (res.data.type == 3) {
							uni.redirectTo({
								url: '/pages/register/shop'
							})
						}
					}
				})
			},
			hotGoods() {
				hotGoods({
					page: this.page
				}).then(res => {
					if (res.status == 1) {
						this.goods_type = res.data.goods_type

					}
				})
			},
			IndexGoods() {
				Home().then(res => {
					if (res.status == 1) {
						this.banner = res.data.banner
					}
				})
			},
			totwPage(url) {
				uni.switchTab({
					url
				})
			},
			toPage(url) {
				uni.navigateTo({
					url: url
				})
			},
			toTarPage(url) {
				uni.switchTab({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss">
	.top {
		background: #fff;
		padding: 10px 0;
		position: sticky;
		top: 0px;
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		z-index: 99;

		.news {
			text-align: right;
			padding-right: 5%;
			position: fixed;
			top: 8px;
			z-index: 99999;
			right: 2%;

			image {
				width: 50rpx;
				height: 50rpx;
			}
		}

		.logo {
			display: flex;
			justify-content: center;
			padding-bottom: 30rpx;
			padding-top: 20rpx;

			image {
				width: 60%;
				height: 90px;
			}
		}

		.search {
			position: relative;
			width: 90%;
			background: #F5F5F5;
			border-radius: 20px;
			margin: 0px auto;
			display: flex;
			align-items: center;
			padding: 0 10px;
			box-sizing: border-box;
			padding-left: 20px;

			image {
				width: 20px;
				height: 20px;
			}

			input {
				width: 80%;
				margin-left: 10px;
				line-height: 35px;
				height: 35px;
				color: #000;
				font-size: 15px;
			}


		}

	}

	.swiper {
		height: 200px;
		border-radius: 10px;

		swiper {
			height: 200px;
		}

		.swiper-item {
			text-align: center;

			image {
				width: 100%;
				margin: 0 auto;
				height: 200px;
				border-radius: 5px;
			}
		}
	}

	.nav {
		display: flex;
		width: 96%;
		margin: 0 auto;
		margin-top: 10px;
		background: #fff;
		border-radius: 8px;
		padding: 10px 0;
		box-sizing: border-box;
		overflow-x: scroll;
		white-space: nowrap;

		.nav-tab {
			display: inline;
			width: 70px;
			margin: 5px 0;

			.navbox {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				width: 70px;
			}

			image {
				width: 50px;
				height: 50px;
				margin-bottom: 6px;
				border-radius: 8px;
			}

			text {
				font-size: 12px;
				color: #666;
			}
		}
	}

	.hot {
		margin-top: 10px;

		.title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 90%;
			margin: 0 auto;
			border-left: 4px solid #FF3C29;
			padding-left: 2%;
			margin-bottom: 10px;

			.name {
				color: #FF3C29;
				font-size: 15px;
				font-weight: bold;
			}

			.more {
				font-size: 12px;
				color: #999999;
			}
		}

		.goods {
			display: flex;
			width: 100%;
			background: #F7F7F7;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 0 10px;
			box-sizing: border-box;

			.goodsitem {
				display: flex;
				flex-direction: column;
				width: 49%;
				background: #fff;
				border-radius: 8px;
				box-sizing: border-box;
				margin-bottom: 10px;

				image {
					width: 100%;
					height: 150px;
					border-radius: 5px;
				}

				.name {
					font-size: 15px;
					width: 100%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-weight: bold;
					padding: 5px 8px;
					box-sizing: border-box;
				}

				.des {
					padding: 0 8px;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					overflow: hidden;
					font-size: 12px;
					color: #777;
				}

				.price {
					color: #FF3C29;
					font-size: 12px;
					padding: 8px 8px 4px;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.pricenum {
						font-size: 15px;
						font-weight: bold;
					}

					.oldprice {
						font-size: 12px;
						color: #777;
						font-weight: normal;
						text-decoration: line-through;
					}

					.sell {
						font-size: 12px;
					}
				}

				.old {
					padding-top: 0;
					padding-bottom: 10px;
				}

				.vipprice {
					font-size: 14px;
				}
			}
		}
	}
</style>